home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / srouted-.000 / srouted- / srouted-0.1pl1 / timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-17  |  2.7 KB  |  114 lines

  1. /* timer.c -- timer support routines */
  2.  
  3. /*
  4.  *  srouted -- silent routing daemon
  5.  *  Copyright (C) 1995 Kevin Buhr
  6.  *
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. #ifndef lint
  23. static char rcsid[] = "$Id: timer.c,v 1.3 1995/02/17 17:42:46 buhr Exp $";
  24. #endif /* not lint */
  25.  
  26. #include "table.h"
  27. #include "error.h"
  28. #include "timer.h"
  29.  
  30.  
  31. /*
  32.  *    Set timeout timer
  33.  */
  34.  
  35. void tm_settimeout( int route )
  36. {
  37.    note1( ERCTM_SETTO, route );
  38.    tb_route[route].tbrt_timer = time(NULL) + TM_TIMEOUT;
  39.    tb_route[route].tbrt_flags &= ~TBRTF_TIMERON;
  40.    tb_route[route].tbrt_flags |= TBRTF_TIMEOUT;
  41. }
  42.  
  43.  
  44. /*
  45.  *    Set garbage collection timer
  46.  */
  47.  
  48. void tm_setgarbcoll( int route )
  49. {
  50.    note1( ERCTM_SETGC, route );
  51.    tb_route[route].tbrt_timer = time(NULL) + TM_GARBCOLL;
  52.    tb_route[route].tbrt_flags &= ~TBRTF_TIMERON;
  53.    tb_route[route].tbrt_flags |= TBRTF_GARBCOLL;
  54. }
  55.  
  56.  
  57. /*
  58.  *    Kill the timer
  59.  */
  60.  
  61. void tm_killtimer( int route )
  62. {
  63.    note1( ERCTM_KILL, route );
  64.    tb_route[route].tbrt_timer = 0;
  65.    tb_route[route].tbrt_flags &= ~TBRTF_TIMERON;
  66. }
  67.  
  68.  
  69. /*
  70.  *    Act on all expired timers, return time of next expiry
  71.  */
  72.  
  73. time_t tm_expire( time_t now )
  74. {
  75.    int rti, nextroute;
  76.    struct tb_route *route;
  77.    time_t next;
  78.  
  79.    next=0;
  80.    for( rti=0; rti<TB_ROUTE_SIZE; rti++ ) {
  81.       route = &tb_route[rti];
  82.       if( (route->tbrt_flags & TBRTF_USED) == 0
  83.      || route->tbrt_flags & TBRTF_KILLED
  84.      || (route->tbrt_flags & TBRTF_TIMERON)==0 )
  85.      continue;
  86.       if( route->tbrt_timer < now+TM_NOW_FUZZ ) {
  87.      switch( route->tbrt_flags & TBRTF_TIMERON ) {
  88.      case TBRTF_TIMEOUT:
  89.         note1( ERCTM_TIMEOUT, rti );
  90.         tb_delroute( rti, NULL );
  91.         break;
  92.      case TBRTF_GARBCOLL:
  93.         note1( ERCTM_GARBCOLL, rti );
  94.         tb_killroute( rti );
  95.         break;
  96.      }
  97.       } else {
  98.      if( next==0 || route->tbrt_timer < next ) {
  99.         next = route->tbrt_timer;
  100.         nextroute = rti;
  101.      }
  102.       }
  103.    }
  104.  
  105.    if( next ) {
  106.       if(tb_route[nextroute].tbrt_flags & TBRTF_TIMEOUT)
  107.      note1( ERCTM_NETO, nextroute );
  108.       else
  109.      note1( ERCTM_NETO, nextroute );
  110.    } else
  111.       note0( ERCTM_NENONE );
  112.    return(next);
  113. }
  114.